package cn.fl.system.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.constant.BaseExceptionConstant;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.system.condition.SysPgCmpDtlQueryCondition;
import cn.fl.system.dto.SysPgInfoDTO;
import cn.fl.system.service.ISysComponentApiService;
import cn.fl.system.service.ISysPgInfoService;
import cn.fl.system.transform.SysPgInfoVOTransform;

/**
 * 系统页面基础信息定义表 客户端服务层接口
 * @author FUJINGRUN
 */
@Service
public class SysPgInfoServiceImpl implements ISysPgInfoService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(SysPgInfoServiceImpl.class);
	
	/**
	 * 组件服务 API暴露服务
	 */
	@Autowired
	private ISysComponentApiService sysComponentApiService;

	@Override
	public String getSysPgCmp(String sysCd, Long roleId, String orgCd, String pgCd, String cmpCd) throws BaseException{
		if(StringUtils.isEmpty(sysCd) || StringUtils.isEmpty(orgCd) || StringUtils.isEmpty(pgCd) || StringUtils.isEmpty(cmpCd)){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		return this.sysComponentApiService.getSysPgCmp(sysCd, roleId, orgCd, pgCd, cmpCd);
	}

	@Override
	public String getSysPgCmpDtl(SysPgCmpDtlQueryCondition condition) throws BaseException{
		if(null == condition 
				||StringUtils.isEmpty(condition.getSysCd()) 
				|| CollectionUtils.isEmpty(condition.getOrgCds()) 
				|| StringUtils.isEmpty(condition.getPgCd()) 
				|| StringUtils.isEmpty(condition.getCmpCd()) 
				|| CollectionUtils.isEmpty(condition.getCmpFldNmList())){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		return this.sysComponentApiService.getSysPgCmpDtl(condition);
	}
	
	
	@Override
	public String getSysPgCmpDtlWithBiz(SysPgCmpDtlQueryCondition condition) throws BaseException{
		if(null == condition 
				|| StringUtils.isEmpty(condition.getSysCd()) 
				|| StringUtils.isEmpty(condition.getOrgCd()) 
				|| StringUtils.isEmpty(condition.getPgCd()) 
				|| StringUtils.isEmpty(condition.getCmpCd()) 
				|| CollectionUtils.isEmpty(condition.getCmpFldNmList())
				|| StringUtils.isEmpty(condition.getBizTypCd())
				|| StringUtils.isEmpty(condition.getBizCd())){
			throw new BaseException(BaseExceptionConstant.BASE_EXCEPTION_CODE_600, BaseExceptionConstant.BASE_EXCEPTION_CODE_600_NAME);
		}
		return this.sysComponentApiService.getSysPgCmpDtlWithBiz(condition);
	}

	@Override
	public Pager searchSysPgInfoListPage(Pager page) throws BaseException {
		page = sysComponentApiService.searchPgInfoListPage(page);
		if(null != page && CollectionUtils.isNotEmpty(page.getResultList())){
			@SuppressWarnings("unchecked")
			List<SysPgInfoDTO> list = (List<SysPgInfoDTO>)page.getResultList();
			if(CollectionUtils.isNotEmpty(list)){
				page.setResultList(SysPgInfoVOTransform.toVOList(list));
			}
		}
		return page;
	}
	
}
